package Master.interfaces;

import java.awt.GridBagConstraints;
import java.awt.Insets;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;

import Master.Task;

/*
 * JPanel extended from PanelItem for displaying tasks
 */
public class TaskPanelItem extends PanelItem{
	private JLabel image = new JLabel(
						new ImageIcon("client_images/gui/task.png"));
	private JLabel task_id = new JLabel("Task ID");
	private JLabel program_name = new JLabel("Program name");
	private JLabel program_filepath = new JLabel("Program path");
	private JLabel arguments = new JLabel("Arguments");
	private JLabel data_name = new JLabel("Data name");
	private JLabel data_filepath = new JLabel("Data path");
	private JLabel output_name = new JLabel("Output name");
	private JLabel time = new JLabel("Estimated time (sec)");
	
	private JLabel task_id_data =new JLabel();
	private JLabel program_name_data = new JLabel();
	private JLabel program_filepath_data =new JLabel();
	private JLabel arguments_data = new JLabel();
	private JLabel data_name_data =new JLabel();
	private JLabel data_filepath_data = new JLabel();
	private JLabel output_name_data = new JLabel();
	private JLabel time_data = new JLabel();

	public TaskPanelItem(Task this_task)
	{
		super(this_task.getTaskID());
		
		String args = "";
		for(String arg:this_task.getArguments())
			args+=arg+" ";
		
		task_id_data.setText(""+this_task.getTaskID());
		program_name_data.setText(this_task.getProgramName());
		program_filepath_data.setText(this_task.getProgramPath());
		arguments_data.setText(args);
		data_name_data.setText(this_task.getDatafileName());
		data_filepath_data.setText(this_task.getDatafilePath());
		output_name_data.setText(this_task.getOutputFileName());
		time_data.setText(""+this_task.getEstimateTime());
		
		initialiseGUI();
	}
	
	private void initialiseGUI()
	{
		this.setBorderStyle(BorderFactory.createEtchedBorder());
		
		GridBagConstraints c = new GridBagConstraints();
		c.fill = GridBagConstraints.HORIZONTAL;
		
		c.gridx = 0;
		c.gridy = 0;
		c.gridheight=8;
		c.insets=new Insets(3,3,3,3);
		//image.setBorder(BorderFactory.createEtchedBorder());
		this.addComponent(image,c);
		c.gridheight=1;
		
		c.insets=new Insets(1,5,1,5);
		c.gridx = 1;
		c.gridy = 0;
		this.addComponent(task_id,c);
		
		c.gridx = 1;
		c.gridy = 1;
		this.addComponent(program_name,c);
		
		c.gridx = 1;
		c.gridy = 2;
		this.addComponent(program_filepath,c);
		
		c.gridx = 1;
		c.gridy = 3;
		this.addComponent(arguments,c);
		
		c.gridx = 1;
		c.gridy = 4;
		this.addComponent(data_name,c);
		
		c.gridx = 1;
		c.gridy = 5;
		this.addComponent(data_filepath,c);
		
		c.gridx = 1;
		c.gridy = 6;
		this.addComponent(output_name,c);
		
		c.gridx = 1;
		c.gridy = 7;
		this.addComponent(time,c);
		
		c.gridx = 2;
		c.gridy = 0;
		this.addComponent(task_id_data,c);
		
		c.gridx = 2;
		c.gridy = 1;
		this.addComponent(program_name_data,c);
		
		c.gridx = 2;
		c.gridy = 2;
		this.addComponent(program_filepath_data,c);
		
		c.gridx = 2;
		c.gridy = 3;
		this.addComponent(arguments_data,c);
		
		c.gridx = 2;
		c.gridy = 4;
		this.addComponent(data_name_data,c);
		
		c.gridx = 2;
		c.gridy = 5;
		this.addComponent(data_filepath_data,c);
		
		c.gridx = 2;
		c.gridy = 6;
		this.addComponent(output_name_data,c);
		
		c.gridx = 2;
		c.gridy = 7;
		this.addComponent(time_data,c);
	}
}
